#ifndef _SERVERMANAGER_SERVERLINK_H_
#define _SERVERMANAGER_SERVERLINK_H_

#include "net/net.h"
#include "app/app.h"
#include "pack/pack.h"
#include "tool/tool.h"
#include "proto/proto.h"

namespace servermanager {

class ServerLink: public net::ISocketHandler {
	public:
		typedef std::list<tool::IRequestClient*> REQUEST_CLIENT_LIST;

	private:
		net::ISocket* socket;

	private:
		REQUEST_CLIENT_LIST request_client_list;

	private:
		tool::IRequestDispatcher* dispatcher;

	public:
		ServerLink(net::ISocket* socket);
		~ServerLink();

	public:
		net::ISocket* GetSocket();

		void AddRequestClient(tool::IRequestClient* client);
		void RemoveRequestClient(tool::IRequestClient* client);

	private: /* Internal */
		void DestroyRequestClient();

	private: /* net::ISocketHandler */
		virtual void OnRead(net::ISocket* socket);
		virtual void OnWrite(net::ISocket* socket);
		virtual void OnClose(net::ISocket* socket);
		virtual void OnConnected(net::ISocket* socket);
		virtual void OnError(net::ISocket* socket, uint32_t error);
};

}

#endif
